/**
YASTACS single user game server interface for clients.

License: GNU General Public License

YASTACS game
Copyright (C) 2012 Kalman Kiss, kiskami@freemail.hu

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Contact author at: kiskami@freemail.hu or
Hungary, 8900 Zalaegerszeg
Kakukkfu u 4.
*/
module server.GameServerInterface;

import Common;

alias string SessionId;
alias long SequenceType;

enum ServerResultCode {
	// first the errors
	GENERAL_ERROR
	, NETWORKING_ERROR
	, BANNED_FROM_SERVER
	// doesn't have the permission th create a new game
	, NOPERM_NEWGAME

	, NOTSUPPORTED

	// warnings range starts here
	, WARNING = 1000

	// ok range starts here
	, OK = 2000
};

struct ServerResult {

	this(ServerResultCode result_code, SessionId session_id, string data, SequenceType res_sequence) {
		result_code_ = result_code;
		session_id_ = session_id;
		data_ = data;
		res_sequence_ = res_sequence;
	}

	@property ServerResultCode result_code() { return result_code_; }
	@property SessionId session_id() { return session_id_; }
	@property string data() { return data_; }
	@property SequenceType res_sequence() {return res_sequence_; }

private:
	ServerResultCode result_code_;
	SessionId session_id_;
	string data_;
	// timestamp?
//	SysTime timestamp_;
	SequenceType res_sequence_;
};

bool wasServerError(ServerResult res) {
	return res.result_code < ServerResultCode.WARNING;
}

bool wasServerWarning(ServerResult res) {
	return (res.result_code > ServerResultCode.WARNING) & (res.result_code < ServerResultCode.OK);
}

bool wasServerOk(ServerResult res) {
	return res.result_code >= ServerResultCode.OK;
}

interface GameServerInterface {

	void setProgressDelegate(progressdelegate pd_);
	void setLogDelegate(logdelegate ld_);

	ServerResult connectToServer(string servername_, string loginname_, string password_);
	ServerResult disconnectFromServer(SessionId session_id_);
	ServerResult startNewGame(SessionId session_id_, string name_, string seed_, GameDifficultyLevel level_, bool violence_);
	ServerResult update(SessionId session_id_, real elapsedTime);
	ServerResult getUniversumData(SessionId session_id_);

	ServerResult getPlayerSpawnData(SessionId session_id_);
//	void 
};
